package com.example.demo.biz;

import com.example.demo.dao.IAdminDao;
import com.example.demo.enums.ResultEnum;
import com.example.demo.exception.AdminException;
import com.example.demo.pojo.Adminuser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/5/25.
 */
@Service
public class AdminBiz {
    @Autowired
    private IAdminDao adminDao;
    @Transactional
    public Adminuser add(Adminuser adminuser) {
        Adminuser adminuser1= adminDao.save(adminuser);
        return adminuser1;
    }
    public List<Adminuser> list(){
        List<Adminuser> all = adminDao.findAll();
        return all;
    }
    public Adminuser findById(Integer id) throws Exception {
        if (id==null){
            throw new AdminException(ResultEnum.NOTNULL);
        }else {
            Adminuser one = adminDao.findOne(id);
            return one;
        }
    }

    public Adminuser login(Adminuser adminuser){
        Adminuser byAnameAndApassword = adminDao.findByAnameAndApassword(adminuser.getAname(), adminuser.getApassword());
        return byAnameAndApassword;
    };
}
